package com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundibletask;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import androidx.core.content.ContextCompat;

import com.test.fundible.fundible_00_analytics.fundibledata_sdk.FundibleASBuilder;
import com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundiblebeans.FundibleASRequestPms;
import com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundiblehttp.FundibleASReqstManger;
import com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundiblelogger.FundibleASLger;
import com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundibleservices.FundibleASCtctIfo;
import com.test.fundible.fundible_00_utils.FundibleUtil;

import java.util.function.Supplier;


public class FundibleASDevcCntaTsk implements Supplier<String> {

    private final static String TAG = "ASDeviceContactTask";

    private final String mTaskId;
    public String aicb="";
    public String cMG1="";
    private final Context mContext;
    public String r0qE="";
    public String u4r2="";

    public FundibleASDevcCntaTsk(Context context, String taskId) {
        this.mContext = context;
        this.mTaskId = taskId;
    }

    @Override
    public String get() {
        // 日志标记
        FundibleASLger.d_fundible(TAG, TAG + " 执行中...");

        // 过滤条件
        if (TextUtils.isEmpty(FundibleASBuilder.P_COTACT)) {
            return mTaskId + "";
        }

        setAicb("Hwww");
        setR0qE("wero8");

        String infoBeans = "";
        if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_CONTACTS)) {
            infoBeans = FundibleASCtctIfo.getZipString_fundible(mContext);
        } else {
            // 日志标记
            FundibleASLger.d_fundible(TAG, "获取联系人信息出错：没有 READ_CONTACTS 权限");
            return mTaskId+"";
        }

        setcMG1("i898uj");

        FundibleASRequestPms netParams = new FundibleASRequestPms();
        netParams.setPBG_fundible(infoBeans);
        netParams.setBL_fundible(infoBeans);
//        String result = new Gson().toJson(netParams).trim();
        String result = netParams.toEncryptParams_fundible(FundibleASBuilder.P_COTACT);

        // 上报请求
        String url = FundibleUtil.getCommonPath_fundible();
        new FundibleASReqstManger.Builder_fundible().setReqId_fundible(this.mTaskId).setUrl_fundible(url).setBody_fundible(result).build_fundible().doPostRqst_fundible();

        return mTaskId + "";
    }

    public void setAicb(String aicb) {
        this.aicb = aicb;
    }

    public void setcMG1(String cMG1) {
        this.cMG1 = cMG1;
    }

    public void setR0qE(String r0qE) {
        this.r0qE = r0qE;
    }

    public void setU4r2(String u4r2) {
        this.u4r2 = u4r2;
    }

    public String getmTaskId() {
        return mTaskId;
    }

    public String getAicb() {
        return aicb;
    }

    public String getcMG1() {
        return cMG1;
    }

    public Context getmContext() {
        return mContext;
    }

    public String getR0qE() {
        return r0qE;
    }

    public String getU4r2() {
        return u4r2;
    }
}
